package com.jf3q.common.vo;

import com.jf3q.common.constant.ResultCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author:xiaojie
 * @create: 2023-04-25 14:10
 * @Description: 统一结果返回
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultVo {

    private Integer code;
    private String message;
    private Object data;

    //返回正确的
    public static ResultVo success(String message, Object data){
        return new ResultVo(ResultCode.SUCCESS.getCode(),message,data);
    }
    public static ResultVo success(){
        return new ResultVo(ResultCode.SUCCESS.getCode(),null,null);
    }
    public static ResultVo success(Object data){
        return new ResultVo(ResultCode.SUCCESS.getCode(),null,data);
    }

    //返回错误的
    public static ResultVo error(String message){
        return new ResultVo(ResultCode.ERROR.getCode(),message,null);
    }

    //自定义异常的时候
    public static ResultVo error(Integer code, String message){
        return new ResultVo(code,message,null);
    }

}
